package com.tommy.jiami.adapter;
import android.content.*;
import android.database.*;
import android.view.*;
import android.widget.*;
import com.tommy.jiami.*;
import com.tommy.jiami.utils.*;

public class PassageAdapter extends CursorAdapter
{
	
	public PassageAdapter(Context context,Cursor c){
		super(context,c);
	}

	@Override
	public View newView(Context context, Cursor c, ViewGroup parent)
	{
		View convertView=LayoutInflater.from(context).inflate(R.layout.item_passage,parent,false);
		ViewHolder holder=new ViewHolder();
		holder.title=(TextView)convertView.findViewById(R.id.passage_item_title);
		holder.detail=(TextView)convertView.findViewById(R.id.passage_item_detail);
		convertView.setTag(holder);
		return convertView;
	}

	@Override
	public void bindView(View convertView, Context context, Cursor c)
	{
		ViewHolder holder=(ViewHolder)convertView.getTag();
		String userPwd=Utils.getUserPassword();
		String titleStr=null,detailStr=null;
		try
		{
			titleStr = Crypt.decryptString(c.getString(c.getColumnIndex("title")), userPwd);
			detailStr = Crypt.decryptString(c.getString(c.getColumnIndex("detail")), userPwd);
		}
		catch (Exception e)
		{}
		holder.title.setText(titleStr);
		holder.detail.setText(detailStr);
	}
		
	class ViewHolder{
		TextView title,detail;
	}
}
